const getters = {
	goodsList: (state) => state.shopcart.goodsList,
	goodsListLength: (state) => state.shopcart.goodsList.length,
	allTotal: (state) => {
		const total = {
			count: 0,
			price: 0,
			checkCount: 0,
			productNum: 0,
		};
		// 遍历店铺
		state.shopcart.goodsList.forEach((item, index) => {
			// 遍历商品
			item.product.forEach((itemProduct, indexProduct) => {
				total.productNum += 1;

				if (itemProduct.checked) {
					// 累加的总数量和总价格
					total.checkCount += 1;
					total.count += itemProduct.count;
					total.price += itemProduct.count * itemProduct.price;
				}
			});
		});
		uni.setTabBarBadge({
			index: 1,
			text: total.productNum.toString(),
		});
		return total;
	},
};
export default getters;
